﻿using System;
using System.Threading;

namespace LockScreen
{
    public class CoreHelper
    {
        /// <summary>
        /// 强制退出程序
        /// </summary>
        public static void DoExit()
        {
            Environment.Exit(0);
        }

        /// <summary>
        /// 执行锁屏及关屏
        /// </summary>
        public static void DoLock(IntPtr handle)
        {
            WinAPI.BlockInput(true);
            WinAPI.LockWorkStation();
            WinAPI.SendMessage(handle, WinAPI.WM_SYSCOMMAND, WinAPI.SC_MONITORPOWER, 2);
            WinAPI.BlockInput(false);
            DoExit();
        }

        /// <summary>
        /// 窗体置顶
        /// </summary>
        /// <param name="handle"></param>
        public static void DoTopMost(IntPtr handle)
        {
            if (handle != WinAPI.GetForegroundWindow())
            {
                WinAPI.SetForegroundWindow(handle);
            }
        }
    }
}
